﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.GuaZhiDuanLianService;

namespace CommunitySystem
{
    public partial class GuaZhiAnPaiWindow : ChildWindow
    {
        private ObservableCollection<int> IDS = new ObservableCollection<int>();
        private int ID;
        private GuaZhiDuanLianServiceClient Client1 =
            new GuaZhiDuanLianServiceClient();
        public ObservableCollection<GuaZhiEmpModel> Models =
            new ObservableCollection<GuaZhiEmpModel>();
        public ObservableCollection<int> EmpIDs =
            new ObservableCollection<int>();
        public GuaZhiEmpModel model = new GuaZhiEmpModel();
        public GuaZhiAnPaiWindow(ObservableCollection<GuaZhiEmpModel> id)
        {
            InitializeComponent();
            Models = id;
            foreach (GuaZhiEmpModel i in Models)
            {
                IDS.Add(i.ID);
                EmpIDs.Add(i.EmpbasicID);
            }
            Client1.ZhiWeiAnPaiCompleted += new EventHandler<ZhiWeiAnPaiCompletedEventArgs>(Client1_ZhiWeiAnPaiCompleted);
            //Client1.GetGuaZhiDuanLianEmpZongModelCompleted += new EventHandler<GetGuaZhiDuanLianEmpZongModelCompletedEventArgs>(Client1_GetGuaZhiDuanLianEmpZongModelCompleted);
            //Client1.GetGuaZhiDuanLianEmpZongModelAsync(0, "", "", list);
            this.DataContext = model;

        }

        void Client1_ZhiWeiAnPaiCompleted(object sender, ZhiWeiAnPaiCompletedEventArgs e)
        {
            this.DialogResult = true;
        }

        //void Client1_GetGuaZhiDuanLianEmpZongModelCompleted(object sender, GetGuaZhiDuanLianEmpZongModelCompletedEventArgs e)
        //{
        //    if(e.Result != null && e.Result.Count > 0)
        //    {
        //        foreach (GuaZhiEmpModel i in e.Result)
        //            EmpIDs.Add(i.EmpbasicID);
        //    }
        //}

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            string id = "";
            foreach (int i in IDS)
            {
                id += i.ToString() + ",";
            }
            if(MessageBox.Show("确定进行挂职安排吗？","提示",MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                Client1.ZhiWeiAnPaiAsync(id.Substring(0, id.Length - 1), model, Models);
            }
            
        }
    }
}
